package com.zmn.plat.admin.controller.channel.brandratio;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import com.zmn.plat.common.exception.PlatException;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.plat.business.interfaces.channel.brand.ratio.ChannelBrandRatioBService;
import com.zmn.plat.model.vo.channel.brand.ratio.ChannelBrandRatioModifyVo;
import com.zmn.plat.model.vo.channel.brand.ratio.ChannelBrandRatioVo;

/**
 * 类描述:渠道品牌系数管理修改控制
 *
 * @author linfeng
 * @since 2020/09/02 11:02
 */
@Controller
@RequestMapping("/channel/brand/ratio/")
public class ChannelBrandRatioModifyController extends ChannelBrandRatioBaseController {
    private Logger logger = LoggerFactory.getLogger(ChannelBrandRatioModifyController.class);

    @Resource
    private ChannelBrandRatioBService brandRatioBService;

    /**
     * 删除渠道品牌关联的系数
     * 
     * @param ids
     * @return
     */
    @RequestMapping(value = "delete")
    @ResponseBody
    public ResponseDTO delete(@RequestParam(value = "channelId", defaultValue = "0") Integer channelId,
        @RequestParam(value = "ids", defaultValue = "0") String ids,
        @RequestParam(value = "priceType", defaultValue = "1") Integer priceType,
        @RequestParam(value = "bizType", defaultValue = "1") Integer bizType) {
        if (StringUtils.isEmpty(ids)) {
            return ResponseDTO.fail("请选择要删除的数据！");
        }

        brandRatioService.deleteByChannelIdAndBrandIdsAndPriceTypeAndBizType(channelId, ids.split(","), priceType, bizType);
        return ResponseDTO.success(ids, "删除成功！");
    }

    /**
     * 添加/修改渠道品牌默认系数
     *
     * @param request
     * @param brandRatioVo
     * @return
     */
    @RequestMapping("addEdit")
    @ResponseBody
    public ResponseDTO addEdit(HttpServletRequest request, @RequestBody ChannelBrandRatioVo brandRatioVo) {
        Integer result = -1;
        try {
            result = brandRatioBService.addEditBrandRatio(getMcStaffRealName(), brandRatioVo);
            return ResponseDTO.success(result,"操作成功！");
        }catch (PlatException e){
            return ResponseDTO.fail(e.getMessage());
        }

    }

    /**
     * 添加或修改渠道品牌分类系数
     *
     * @param request
     * @param brandRatioModifyVo
     * @return
     */
    @RequestMapping("categoryRatioAddEdit")
    @ResponseBody
    public ResponseDTO addEditCategoryRatio(HttpServletRequest request, @RequestBody ChannelBrandRatioModifyVo brandRatioModifyVo) {
        Integer result = -1;
        try {
            result = brandRatioBService.addEditCategoryRatio(getMcStaffRealName(), brandRatioModifyVo);
            return ResponseDTO.success(result,"操作成功！");
        }catch (PlatException e){
            return ResponseDTO.fail(e.getMessage());
        }
    }
}
